package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.act.model.common.ArchiModel;
import edu.pku.sei.act.model.mote.Mote;

public class DeleteMoteCommand extends Command {

	private ArchiModel model;
	private Mote mote;

	public DeleteMoteCommand(Mote mote) {
		super("Delete Mote");
		this.mote = mote;
		if (mote.getContainer() instanceof ArchiModel) {
			model = (ArchiModel) mote.getContainer();
		}
	}

	public boolean canExecute() {
		return mote != null &&  model != null;
	}

	public void execute() {
		if (model != null) {
			model.getRootElements().remove(mote);
		}
		mote.setContainer(null);
	}

	public void undo() {
		if (model != null) {
			mote.setContainer(model);
			model.getRootElements().add(mote);
		}
	}

}
